/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.cloudfactory.service;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.cloudfactory.entity.CloudfactoryUser;
import com.thinkgem.jeesite.modules.cloudfactory.entity.CloudfactroyOrder;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.cloudfactory.dao.CloudfactroyOrderDao;

/**
 * 单表生成Service
 * @author ThinkGem
 * @version 2018-09-08
 */
@Service
@Transactional
public class CloudfactroyOrderService extends CrudService<CloudfactroyOrderDao, CloudfactroyOrder> {
	@Autowired
	private CloudfactroyOrderDao cloudfactroyOrderDao;
	public CloudfactroyOrder get(String id) {
		return super.get(id);
	}
	
	public List<CloudfactroyOrder> findList(CloudfactroyOrder cloudfactroyOrder) {
		return super.findList(cloudfactroyOrder);
	}
	
	public Page<CloudfactroyOrder> findPage(Page<CloudfactroyOrder> page, CloudfactroyOrder cloudfactroyOrder) {
		return super.findPage(page, cloudfactroyOrder);
	}
	
	@Transactional(readOnly = false)
	public void save(CloudfactroyOrder cloudfactroyOrder) {
		super.save(cloudfactroyOrder);
	}
	
	@Transactional(readOnly = false)
	public void delete(CloudfactroyOrder cloudfactroyOrder) {
		super.delete(cloudfactroyOrder);
		
	}
	
	@Transactional(readOnly = false)
	public int update1(String orderNo) {
		CloudfactroyOrder order = new CloudfactroyOrder();
		order.setOrderNo(orderNo);
		List<CloudfactroyOrder> cloudfactroyOrders = cloudfactroyOrderDao.findByOrderNo(order);
		for(CloudfactroyOrder c :cloudfactroyOrders){
			c.setStatus("1");
		cloudfactroyOrderDao.update(c);
		}
		return 1;
	}

	public List<CloudfactroyOrder> findByOrderNo(CloudfactroyOrder cloudfactroyOrder) {
		CloudfactroyOrder order = new CloudfactroyOrder();
		order.setOrderNo(cloudfactroyOrder.getOrderNo());
		return cloudfactroyOrderDao.findByOrderNo(order);
	}

	public void update(CloudfactroyOrder c) {
		cloudfactroyOrderDao.update(c);
		
	}
	/**
	 * 
	* @Title: getOrdersByUser
	* @Description: 查询当前登陆账户的所有订单
	* @param @param request
	* @param @return    参数
	* @return List<CloudfactroyOrder>    返回类型
	* @throws
	 */
	public List<CloudfactroyOrder> getOrdersByUser(HttpServletRequest request) {
		CloudfactoryUser cloudfactoryUser = (CloudfactoryUser) request.getSession().getAttribute("cloudfactoryUser");
		User user = new User();
		user.setId(cloudfactoryUser.getId());
		CloudfactroyOrder cloudfactroyOrder = new CloudfactroyOrder();
		cloudfactroyOrder.setUser(user);
		
		return cloudfactroyOrderDao.findList(cloudfactroyOrder);
	}

	public List<CloudfactroyOrder> count(CloudfactroyOrder cloudfactroyOrder) {
		
		return cloudfactroyOrderDao.count(cloudfactroyOrder);
	}
	
}